from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field, validator


class DateRange(BaseModel):
    start_date: str = Field(..., description="开始日期")
    end_date: str = Field(..., description="结束日期")

    @validator('start_date')
    def start_date_check(cls, v):
        try:
            datetime.strptime(v, '%Y-%m-%d')
        except ValueError:
            raise ValueError("Incorrect data format, should be YYYY-MM-DD")
        return v

    @validator('end_date')
    def end_date_check(cls, v):
        try:
            datetime.strptime(v, '%Y-%m-%d')
        except ValueError:
            raise ValueError("Incorrect data format, should be YYYY-MM-DD")
        return v
